<style lang="scss" scoped="">
  @import '../../styles/variables';


</style>

<template>
  <div>
    <div class="list-bar-tools">
      <div class="flex">
        <el-input placeholder="" v-model="filter.ip" class="list-bar-tools-input" size="mini" clearable="">
          <template slot="prepend">ip</template>
        </el-input>
        <el-input placeholder="" v-model="filter.nodeName" class="list-bar-tools-input" size="mini"
                  clearable="">
          <template slot="prepend">节点名称</template>
        </el-input>

        <el-button size="mini" type="primary" plain="" icon="el-icon-search" @click="searchSubmit"></el-button>

      </div>
    </div>
    <el-table
      :data="nodeList"
      border=""
      style="width: 100%">
      <el-table-column
        prop="ip"
        label="节点IP">
      </el-table-column>
      <el-table-column
        prop="port"
        label="节点端口">
      </el-table-column>
      <el-table-column
        prop="nodeName"
        label="节点名">
      </el-table-column>

      <el-table-column
        label="状态">
        <template slot-scope="scope">
          <el-tag size="mini" :type="scope.row.enable?'success':'danger'">{{scope.row.enable ? '可用' : '不可用'}}</el-tag>
        </template>
      </el-table-column>

    </el-table>

    <div class="pagination">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="1"
        :page-sizes="[10, 50, 100]"
        :page-size="filter.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="nodeCount">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import utils from '@/utils/utils';
  import {nodeService} from '@/api/index';
  import {mapGetters} from 'vuex';

  export default {
    data() {
      return {
        filter: {
          pageNo: 1,
          pageSize: 10,
          start: 0,
          ip: '',
          nodeId: '',
          searchNodeName: ''
        },
        nodeCount: 0,
        nodeList: [],
        ip: '',
        nodeName: ''
      };
    },
    computed: {
      currentNodeId() {
        return this.$route.params.nodeId;
      }
    },
    watch: {
      'filter': {
        handler: function () {
          this.getNodeList();
        },
        deep: true
      }
    },
    components: {},
    methods: {
      handleCurrentChange(currentPageNo) {
        this.filter.start = (currentPageNo - 1) * this.filter.pageSize;
      },
      handleSizeChange(pageSize) {
        this.filter.pageSize = pageSize;
        localStorage.setItem('node-status-page-size', pageSize);
      },
      getNodeList() {
        if (!this.currentNodeId) {
          return false;
        }
        nodeService.getNodeStatusData(this.filter).then(res => {
          this.nodeCount = res.data.total;
          this.nodeList = res.data.rows;
        });
      },
      searchSubmit() {
        this.getNodeList();
        // Object.assign(this.filter, {ip: this.ip, searchNodeName: this.nodeName});
      }
    },
    created() {
      let oldPageSize = localStorage.getItem('node-status-page-size');
      if (!oldPageSize) {
        oldPageSize = 10;
      }
      this.filter.pageSize = Math.floor(oldPageSize);
    },
    mounted() {
      this.filter.nodeId = this.currentNodeId;
    }
  };
</script>
